Skip to main content

Working with collections

Retrieve a list of collections

To retrieve a list of collections in a database, connect to the database and call GetCollectionsAsync().

using (var transport = HttpApiTransport.UsingBasicAuth(new Uri(url), dbName, username, password))
{
using (var db = new ArangoDBClient(transport))
{
// Retrieve a list of collections
var response = await db.Collection.GetCollectionsAsync();
}
}

Create a collection

To create a new collection, connect to the database and call PostCollectionAsync().

using (var transport = HttpApiTransport.UsingBasicAuth(new Uri(url), dbName, username, password))
{
using (var db = new ArangoDBClient(transport))
{
// Set collection properties
var body = new CollectionApi.Models.PostCollectionBody()
{
Type = CollectionApi.Models.CollectionType.Document,
Name = "MyCollection"
};
// Create the new collection
var response = await db.Collection.PostCollectionAsync(body, null);
}
}

Delete a collection

To delete a collection, connect to the database and call DeleteCollectionAsync(), passing the name of the collection to be deleted as a parameter. Make sure to specify the correct collection name when you delete collections.

using (var transport = HttpApiTransport.UsingBasicAuth(new Uri(url), dbName, username, password))
{
using (var db = new ArangoDBClient(transport))
{
// Delete the collection
var response = await db.Collection.DeleteCollectionAsync("MyCollection");
}
}
 
Help us improve

Anything unclear or buggy in this tutorial? Provide Feedback